<?php
namespace app\index\middleware;
use think\Response;

/**
 * 全局跨域请求处理
 * Class CrossDomain
 * @package app\middleware
 */

class CrossDomain
{
    public function handle($request, \Closure $next)
    {
        header('Access-Control-Allow-Origin: *');
        // header('Access-Control-Allow-Origin: http://utp.xtxcm.com');
       
        header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE');
        header('Access-Control-Allow-Headers: Authorizationpas,platform, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With,Token,rToken,bdtk,boundary,sign');
        //header('Access-Control-Expose-Headers', 'Authorization, authenticated');
        //处理跨域Options预检请求
        if (strtoupper($request->method()) == "OPTIONS") {
            header('Access-Control-Max-Age: 86400');
            exit;
        }
        return $next($request);
    }
}
